<template>

  <div class="news-contianer">
    <div class="news-list">
      <div class="news-item" v-for="item in newsList" :key="item.id" @click="toNewsDetail(item.id)">
        <img :src="item.thumb" width="130px" height="110px">
        <div class="news-detial-container">
          <div class="news-title">{{item.title}}</div>
          <div class="news-detail">{{item.synopsis}}</div>
          <div class="news-time">{{item.addtime}}</div>
        </div>
      </div>
    </div>
    <div style="height: 44px"></div>
    <router-view></router-view>
  </div>
</template>

<script>
import { getNewsList } from 'api/main'

export default {
  data () {
    return {
      newsList: []
    }
  },
  created() {
    this._getNewsList()
  },
  methods: {
    toNewsDetail(id) {
      this.$router.push({
        path: `/news/${id}`
      })
    },
    _getNewsList() {
      getNewsList().then((res) => {
        this.newsList = res
      })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped scoped lang="stylus" rel="stylesheet/stylus">

@import "~common/stylus/mixin"

.news-contianer
  .news-list
    width: 100%
    margin: 0 auto;
    .news-item
      display: flex
      padding 10px
      margin-top: 10px
      background-color: #fff
      img
        object-fit: cover;
        margin-right: 10px
      .news-detial-container
        width: calc(100% - 140px)
        .news-title
          font-size: 16px
          line-height: 25px
          height: 50px
          font-weight: 500;
          line-no-wrap(2)
        .news-time
          font-size: 12px
          height: 20px
          line-height: 20px
          color: #999
        .news-detail
          font-size: 12px
          color: #999
          line-height: 20px
          height: 40px
          line-no-wrap(2)

</style>
